.data:

  a:
    .word 0x1
  b:
    .word 0x2
  c:
    .word 0xA
  address:
    .word CONTINUE24

.text:

//add2 instr
movi %r0, 2 //put 2 into %r0
movi %r1, 3 //put 2 into %r1
add2 %r0, %r1 //r0: 2, r1: 3 --> r0 = 5
movi %r2, 5 //put 5 into %r2
be %r2, %r0, CONTINUE1 ///if expected and actual value same, continue
jmp FAIL //else jump to fail

//addi instr
CONTINUE1:
  addi %r0, 5 //r0 = 10
  movi %r2, 10 //use %r2 as tester
  be %r2, %r0, CONTINUE2 //if expected and actual value same, continue
  jmp FAIL //else jump to fail

//sub2 instr
CONTINUE2:
  movi %r1, 10 //r1 = 10
  sub2 %r0, %r1 // r0 = 0
  movi %r2, 0 //r2 as tester
  be %r2, %r0, CONTINUE3 //if expected and actual value same, continue
  jmp FAIL //else go to fail

//add3 instr
CONTINUE3:
  movi %r1, 1 //put 1 into r1
  movi %r2, 10 //pur 10 into r2
  add3 %r0, %r1, %r2 //if r2 = 10, r0 = 11
  movi %r2, 11 //use r2 as tester
  be %r2, %r0, CONTINUE4 //if expected and actual value same, continue
  jmp FAIL //else go to fail

//sub3 instr
CONTINUE4:
  sub3 %r0, %r0, %r2 //r0 = 0
  movi %r2, 0 //0 to r2 as tester
  be %r2, %r0, CONTINUE5 //if expected and actual value same, continue
  jmp FAIL //else go to fail

//subi instr
CONTINUE5:
  movi %r0, 10 //put 10 into r0
  subi %r0, 10 //r0 = 0
  movi %r2, 0 //use r2 = 0 as tester
  be %r2, %r0, CONTINUE6 //if expected and actual value same, continue
  jmp FAIL //else go to fail

 //nor2
CONTINUE6:
  movi %r1, -2 //r1--> 1111....1110
  movi %r2, -2 //r2 --> 1111...1110
  nor2 %r1, %r2 //r1 --> 0000...0001
  movi %r2, 1 //use r1 = 000...0001 as tester
  be %r2, %r1, CONTINUE7 //if expected and actual value same, continue
  jmp FAIL //else go to fail

//nor3 instr
CONTINUE7:
  movi %r3, -2 //r3--> 1111....1110
  movi %r2, -2 //r2--> 1111....1110
  nor3 %r1, %r3, %r2 //r1 --> 0000...0001
  movi %r2, 1 //r1 --> 0000...0001
  be %r2, %r1, CONTINUE8 //if expected and actual value same, continue
  jmp FAIL //else go to fail

//nori instr
CONTINUE8:
  nori %r3, -2 //r3 --> 1111...1110
  movi %r2, 1 //r2 --> 0000...0001
  be %r2, %r1, CONTINUE9 //if expected and actual value same, continue
  jmp FAIL //else go to fail

//sll2 instr
CONTINUE9:
  movi %r0, 3 // r0 = 3
  movi %r1, 2 // r1 = 2
  sll2 %r0, %r1 //r0 = 12
  movi %r2,12 //check if 3 << 2 = 12
  be %r2, %r0, CONTINUE10 //if expected and actual value same, continue
  jmp FAIL//else go to fail

//sll3 instr
CONTINUE10:
  movi %r2, 3 //r2 = 3
  movi %r1, 2 //r1 = 2
  sll3 %r0, %r1, %r2 //put 2 << 3 into r0
  movi %r2, 16 //check if 2 << 3  = 16
  be %r2, %r0, CONTINUE13 //if expected and actual value same, continue
  jmp FAIL//else go to fail

//slli instr
CONTINUE13:
  movi %r0, 4 //r0 = 4
  slli %r0, 3 //r0 = 4 << 3
  movi %r2, 32 //check if 4 << 3 = 32
  be %r0, %r2, CONTINUE14 //if expected and actual value same, continue
  jmp FAIL//else go to fail

//slr2 instr
CONTINUE14:
  movi %r0, 4 //r0 = 4
  movi %r1, 1 //r1 = 1
  slr2 %r0, %r1 //r0 = 4 >> 1
  movi %r2, 2 //check if 4 >> 1 = 2
  be %r2, %r0, CONTINUE15 //if expected and actual value same, continue
  jmp FAIL//else go to fail

//slr3 instr
CONTINUE15:
  movi %r1, 16 //r1 = 16
  movi %r0, 3 //r0 = 3
  slr3 %r3, %r1, %r0 //r3 = 16 >> 3
  movi %r2, 2 //check if 16 >> 3 is 2
  be %r2, %r3, CONTINUE16 //if expected and actual value same, continue
  jmp FAIL//else go to fail

//slri instr
CONTINUE16:
  movi %r1, 16 //r1 = 16
  slri %r1, 3 //r1 = 16 >> 3
  movi %r2, 2 //check if 16 >> 3 is 2
  be %r2, %r1, CONTINUE17 //if expected and actual value same, continue
  jmp FAIL//else go to fail

  //ldl instr
CONTINUE17:
  ldl %r3, a //r3 = label a = 1
  movi %r2, 1 //put 1 into r2 for testing
  be %r2, %r3, CONTINUE18 //if expected and actual value same, continue
  jmp FAIL//else go to fail

  //ld instr
CONTINUE18:
  ld  %r1, 0(%r3) // r1 = label b = 2
   movi %r2, 2 //put 2 into r2 to check against label b
  be %r2, %r1, CONTINUE19 //if expected and actual value same, continue
  jmp FAIL//else go to fail

  //stl instr
CONTINUE19:
  movi %r0, 7 //r0 = 7
  stl %r0, a  // store 7 at label a
  ldl %r3, a   // r3 = label a
  movi %r2, 7 //check if label a value == 7
  be %r2, %r3, CONTINUE20 //if expected and actual value same, continue
  jmp FAIL//else go to fail

  //st instr
CONTINUE20:
  movi %r3, 20 //put 20 into r3
  movi %r1, 1 //put 1 into r1
  st  %r3, 1(%r1) // store 1 at label c (at address 1+1)
  ldl %r3, c  // r3 = label c value
  movi %r2, 20 //check if label c is 20
  be %r2, %r3, CONTINUE21 //if expected and actual value same, continue
  jmp FAIL//else go to fail

  //mov instr
CONTINUE21:
  movi %r0, 50 //put 50 into r0
  mov %r1, %r0 //put r0 into r1
  be %r0, %r1, CONTINUE22 //if expected and actual value same, continue
  jmp FAIL//else go to fail

 //ble instr
CONTINUE22:
  movi %r0, 4 //put 4 into r0
  movi %r1, 5 //put 5 into r1
  ble %r0, %r1, CONTINUE23 //check if r0 is less than or equal to r1
  jmp FAIL//else go to fail

  //jmpreg instr
CONTINUE23:
  ldl %r0, address //load address label into r0
  jmpreg %r0 //jump to the r0 register's value
  jmp FAIL //otherwise jump to fail

  //set pseudo-instr
CONTINUE24:
  set %r0, 0x3DEADBEEF //set r0 to constant 0x3deadbeef
  set %r1, 0x3FFFFFFFF //set r1 to constant 0x3FFFFFFFF
  ble %r0, %r1, CONTINUE25 //if expected and actual value same, continue
  jmp FAIL//else go to fail

  //call pseudo-instr
CONTINUE25:
  call foo //call the foo function
  movi %r0, 28 //put 28 into r0
  be %r0, %r3, CONTINUE26 //if expected and actual value same, continue
  jmp FAIL//else go to fail

  //foo function, test function call protocol and return pseudo instr
foo:
	movi %r3, 28 //foo function moves 28 into r3
	return //return pseudo-instr

//ini and outi instr
CONTINUE26:
  movi %r0, 2 //put 2 into r0
  outi %r0, 2 //output r0 to channel 2
  ini  %r1, 2 //read in channel 2 to r1
  be %r0, %r1, CONTINUE27 //if expected and actual value same, continue
  jmp FAIL//else go to fail

//in and out intr
CONTINUE27:
   movi %r0, 3 //put 3 into r0
   movi %r1, 1 //put 1 into r1
   out %r0, %r1 //output contents of r1 to channel in r0
   in %r2 , %r0 //read in contents of channel in r0 to r2
   be %r0, %r1, CONTINUE28 //if read == written val, success
   jmp FAIL //else faliure

CONTINUE28:




//success!
  jmp SUCCESS

//if everything is successful, set some flag and halt
SUCCESS:
  movi %r0, 1
  movi %r1, 1
  movi %r2, 1
  movi %r3, 1
  halt

//if something fails, set some flags anf halt
FAIL:
  movi %r0, -1
  movi %r1, -1
  movi %r2, -1
  movi %r3, -1
  halt



//C:\Users\Miller_Lab\workspace\Assembler\tester_i.coe
